<?php
//发布图文 codecontain 为 1、3
session_start();
require('../conn.php');
require('../functions.php');
require('admin.php');
//获取code和title
$codeinfo = $mysql->query("select code,title from `codetype` where containvideo=1 or containvideo=3");
if ($_POST) {
    $user = [];
    //获取机器人
    $robot = $mysql->query("select `id` from `user` WHERE `isrobot`=1 ORDER BY rand() limit 1");
    $user['uid'] = $robot[0]['id'];
    $user['content'] = guolv($_POST['title']);
    $user['img'] = guolv($_POST['content']);
    $user['pnum'] = guolv($_POST['psum']);
    $user['cnum'] = guolv($_POST['cnum']);
    $user['snum'] = guolv($_POST['snum']);
    $user['day'] = date("Y-m-d",time());
    $user['code'] = $_POST['code'];
    $user['flag'] = $_POST['flag'];
    $user['type'] = $_POST['type'];
    $user['forward'] = $_POST['forward'];
    $user['top'] = 3;//后台添加的文章加入到待发布列表
    $codetitle = $mysql->query("select title from codetype WHERE code={$user['code']}");
    $user['code_content'] = $codetitle[0]['title'];
    $picsArr = explode(">",$user['img']);
    $pics = [];
    foreach($picsArr as $pic){
        if($pic != ""){
            $pics[] = cut($pic,"src=\\\"","\\\"");
        }
    }
    $user['img'] = "";
    foreach($pics as $pic){
        $user['img'] .= $pic.",";
    }
    $newSql = "insert into `news`".arr2s($user);
    $res = $mysql->execute($newSql);
    if($res){
        echo "<script>alert('新增成功')</script>";
        echo "<script>location.href='addpublish.php'</script>";
        exit;
    }
} ?>

<?php include('head.php') ?>
<link rel="stylesheet" href="../editor/themes/default/default.css"/>
<link rel="stylesheet" href="../editor/plugins/code/prettify.css"/>
<script charset="utf-8" src="../editor/kindeditor.js"></script>
<script charset="utf-8" src="../editor/lang/zh_CN.js"></script>
<script charset="utf-8" src="../editor/plugins/code/prettify.js"></script>
<script charset="utf-8" src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>
 <script>
    KindEditor.ready(function (K) {
        var editor1 = K.create('textarea[name="content"]', {
            cssPath: '../editor/plugins/code/prettify.css',
            uploadJson: '../editor/php/upload_json.php',
            fileManagerJson: '../editor/php/file_manager_json.php',
            allowFileManager: true,
            filterMode: false,//是否开启过滤模式
            allowImageUpload: true,
        });
        prettyPrint();
    });

</script>

<div class="container-fluid">
    <div class="row-fluid">
        <?php
        include('left.php'); ?>
        <div class="span9">
            <h1 class="page-title">发表动态</h1>

            <div class="well">
                <ul class="nav nav-tabs">
                    <li class="active"><a href="#home" data-toggle="tab">发布</a></li>
                    <li class="active">发布成功后到已审核列表查看</li>
                </ul>
                <div id="myTabContent" class="tab-content">
                    <div class="tab-pane active in" id="home">
                        <form id="tab" action="addpublish.php" method="post">
                            <label>content(发表内容)</label>
                            <input type="text" name="title" style="width:500px">
                        <textarea value="Smith" rows="10" name="content"
                                  style="width:800px;height:400px;visibility:hidden;"></textarea>
                            <label></label>
                            <label>type(2--美图；3--纯文)</label>
                            <select name="type">
                            	<option value="2">2</option>
                            	<option value="3">3</option>
                            </select>
                            <label>code(频道分类)</label>
                            <select name="code">
                                <?php foreach($codeinfo as $code):?>
                            	<option value="<?=$code['code']?>"><?=$code['title']?></option>
                                <?php endforeach;?>
                            </select>
                            <label>flag(1--普通 2--长图 3--gif)</label>
                            <select name="flag">
                            	<option value="1">1</option>
                            	<option value="2">2</option>
                            	<option value="3">3</option>
                            </select>
                            <label>psum(点赞)</label>
                            <input type="text" name="psum" style="width:500px" >
                            <label>cnum(评论)</label>
                            <input type="text" name="cnum" style="width:500px" >
                            <label>snum(赠送)</label>
                            <input type="text" name="snum" style="width:500px" >
                            <label>forward</label>
                            <input type="text" name="forward" style="width:500px" >
                            <br>
                            <button class="btn btn-primary"><i class="icon-save"></i> 保存</button>
                        </form>
                    </div>
                </div>

            </div>

        </div>
    </div>


</div>
<script src="lib/bootstrap/js/bootstrap.js"></script>
</body>
</html>